#ifndef RGN_H
#define RGN_H

#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>

#include "FastMemcpy.h"
#include "detr.h"
#include "global.h"
#include "hi_buffer.h"
#include "hi_common.h"
#include "hi_common_region.h"
#include "hi_common_sys.h"
#include "hi_common_vb.h"
#include "hi_common_video.h"
#include "hi_math.h"
#include "hi_mpi_region.h"
#include "hi_mpi_sys_mem.h"
#include "hi_mpi_vb.h"
#include "hi_mpi_vgs.h"
#include "hi_mpi_vpss.h"
#include "sat.h"
#include "securec.h"

class RGN
{
   public:
    RGN();
    ~RGN();

    hi_s32 Init(td_s32 chn_num, hi_rgn_handle _handle, ot_rgn_type switch_type);
    hi_s32 destroy_region();

    hi_s32 set_attr(bbox_t box, uint32_t color);
    hi_s32 set_lineex_chn_attr(const std::vector<Vector> &vertices, td_u32 color);

    hi_s32 attach_to_chn();
    hi_s32 detach_from_chn();
    hi_s32 get_chn_display_attr();
    hi_s32 set_chn_display_attr();

    hi_s32 draw_NonRecognitionPoly(td_s32 chn_num,std::vector<Polygon>& polys);
    hi_s32 clear_NonRecognitionPoly(std::vector<Polygon>& polys);

   private:
    hi_rgn_handle handle;
    hi_mpp_chn chn;
    hi_rgn_chn_attr chn_attr;
    hi_rgn_type type;
    hi_rgn_attr region;
    bool attach_state = 0;

    hi_s32 set_cover_chn_attr(bbox_t box, uint32_t color);
    hi_s32 set_corner_rect_chn_attr(bbox_t box, uint32_t color);

    int roundDownToMultipleOfFour(int num);
};

#endif